package com.sky.service.impl;

import com.sky.entity.AddressBook;
import com.sky.mapper.AddressMapper;
import com.sky.result.Result;
import com.sky.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AddressServiceImpl implements AddressService {
    @Autowired
    private AddressMapper addressMapper;
    @Override
    public Result<String> add(AddressBook addressBook) {
        return addressMapper.add(addressBook);
    }

    @Override
    public List<AddressBook> selectAll() {
        return addressMapper.selectAll();

    }

    @Override
    public AddressBook getDefault() {
        return addressMapper.getDefault();
    }

    @Override
    public AddressBook getById(Long id) {
        return addressMapper.getById(id);
    }

    @Override
    public void deleteById(Long id) {
        addressMapper.deleteById(id);
    }

    @Override
    public void setDefault(AddressBook addressBook) {
        addressMapper.updateAllDefault(addressBook);
        Long id = addressBook.getId();
        addressMapper.setDefault(id);

    }
}
